package com.iot.ammeter.config;

import com.iot.ammeter.utils.SnowFlakeIdWorker;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.client.RestTemplate;

import java.text.SimpleDateFormat;
import java.util.Random;
import java.util.logging.SimpleFormatter;

/**
 * @ClassName: BeanConfig
 * @Author: Basil
 * @Date: 2021/9/26 下午3:14
 * @Version: 1.0
 **/
@Configuration
public class BeanConfig {

    /**
     * id生成
     *
     * @return SnowFlakeIdWorker
     */
    @Bean
    public SnowFlakeIdWorker snowFlakeIdWorker() {
        return new SnowFlakeIdWorker(0, 0);
    }

    /**
     * 随机数
     *
     * @return Random
     */
    @Bean
    public Random createRandom() {
        return new Random();
    }

    /**
     * security中的 BCryptPasswordEncoder 加密算法
     * @return BCryptPasswordEncoder
     */
    @Bean
    public BCryptPasswordEncoder createPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }

    /**
     * 日期
     * @return
     */
    @Bean
    public SimpleDateFormat simpleDateFormat() {
        return new SimpleDateFormat("yyyy_MM_dd");
    }

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}